#ifndef _GLOBAL_H
#define _GLOBAL_H

//#define DEBUG

#ifdef DEBUG
#define debug(...) printf( __VA_ARGS__) 
#else
#define debug(...)
#endif

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include <semaphore.h>
#include <assert.h>

#include "miniadns.h"
#include "hash_table.h"
#include "queue.h"
#include "list.h"

#define MAX_HEADER 1024
#define BUFFER_SIZE 1000000
#define HEADER_SIZE 20000
#define MAX_CONN_THREAD 50

#define MAX(a, b) (a) > (b) ? (a) : (b)
#define MIN(a, b) (a) < (b) ? (a) : (b)

typedef struct conn_t {
	char				*url;
	int					sockfd;
	int					length, nread, header_finish;
	char				buffer[BUFFER_SIZE];
	char				header[HEADER_SIZE];
} conn_t;

typedef struct global_t {
	conn_t 			*conn;
	char			*start_url;
	hashtable		*url_table, *host_table;
	queue			*url_queue, *conn_queue;
	list			dl_list;
	fd_set			rset, dns_set;
	pthread_t		qtid, ctid[MAX_CONN_THREAD], dtid;
	struct dns		*dns;
	int				max_conn, count;
	sem_t			usem, dsem, csem;
} global_t;

#endif
